import 'package:deer/main/main_page.dart';
import 'package:deer/login/login_router.dart';
import 'package:deer/routers/router_init.dart';
import 'package:deer/widgets/404.dart';
import 'package:deer/widgets/webview_page.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:deer/store/store_router.dart';

class Routes {

  static String mainPage = '/main';
  static String webViewPage = '/webView';

  static List<IRouterProvider> _listRouter = [];
  
  static void configureRoutes(Router router) {
    /// 指定路由跳转错误返回页
    router.notFoundHandler = Handler(
      handlerFunc: (BuildContext context, Map<String, List<String>> params) {
        debugPrint('未找到目标页');
        return WidgetNotFound();
      }
    );

    router.define(mainPage, handler: Handler(handlerFunc: (_,params) => MainPage()));

    router.define(webViewPage, handler: Handler(handlerFunc: (_, params) {
      String title = params['title']?.first;
      String url = params['url']?.first;
      return WebViewPage(title: title, url: url);
    }));

    _listRouter.clear();
    /// 各自路由由各自模块管理，统一在此初始化
    _listRouter.add(LoginRouter());
    _listRouter.add(StoreRouter());

    /// 初始化路由
    _listRouter.forEach((routerProvider) {
      routerProvider.initRouter(router);
    });
  }
}